/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-09-13
 * Time: 20:16
 */
public class Test {
    public static int binarySearch (int[] array, int k) {
        int left = 0;
        int right = array.length - 1;
        while(left <= right) {
            int mid  = left + ((right - left) / 2);
            if (array[mid] > k) {
                right = mid - 1;
            } else if (array[mid] < k) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = {15, 43, 59, 72, 88};
        System.out.println(binarySearch(array, 59));
        System.out.println(binarySearch(array, 101));
    }
}
